<?php

class Model_DbTable_Products_Price_Flexpricehistory extends Zend_Db_Table_Abstract {

	protected $_name = 'product_flex_price_history';

	/**
	 * @version 2014-07-01
	 * @author Leo
	 * @param int $idHistory
	 */
	public function getHistory( $idHistory){

		$row = $this->fetchRow("`id_history` = ". $idHistory);
		if(!$row) return false;
		return $row->toArray();

	}
	/**
	 * @version 2014-07-01
	 * @author Leo 
	 * @param int $idProduct
	 * @param int $idCategory
	 * @param date $dateChange
	 * @param float $priceHistory
	 * insert flex history into product_flex_price_history
	 */

	public function addHistory( $idProduct , $idCategory , $dateChange , $priceHistory){

		$data = array(
					
				"id_product" =>  $idProduct ,
				"id_category" =>  $idCategory ,
				"date_change" =>  $dateChange ,
				"price_history" =>  $priceHistory

		);
		$this->insert($data);

	}
	/**
	 * @version 2014-07-01
	 * @author Leo
	 * @param int $idProduct
	 * @param int $typePrice
	 * @param date $dateChange
	 * @param float $priceHistory
	 * update flex history into product_flex_price_history
	 */
	public function updateHistory(  $idHistory ,  $idProduct , $idCategory , $dateChange , $priceHistory){
		$data = array(
					
				"id_product" =>  $idProduct ,
				"id_category" =>  $idCategory ,
				"date_change" =>  $dateChange ,
				"price_history" =>  $priceHistory

		);
			
		$this->update($data,"`id_history` = ". $idHistory);
	}
	/**
	 * @version 2014-07-01
	 * @author Leo 
	 * @param int $idHistory
	 * delect history by id
	 */
	public function deleteHistory( $idHistory){

		$this->delete("`id_history` = ". $idHistory);

	}
	/**
	 * @version 2014-07-01
	 * @author Leo 
	 * @param int $idHistory
	 * list all
	 */
	public function listAll(){

		$rows =$this->fetchAll("1","id_history DESC ");
		if(!$rows) return false;
		return $rows->toArray();

	}
}

?>